import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export const store = new Vuex.Store({
    // 存放数据源，全局共享的数据
    state: {
        userid: '',
        token: '',
        username: '',
        // 存储用户成功登录的信息
        userinfo: [],
        count: 1,
        total: 0,
        // 购物车选中的商品
        cartlist:[]
    },
    // 用于修改statestate常量中保存的属性的状态
    mutations: {
        // 获取到userid,修改state
        add(state, step) {
            state.userid = step
        },
        changename(state, step) {
            // state.username=step
            // 把用户名存在session
            // sessionStorage.setItem("username", step)
            state.username = step
        },
        save(state, step) {
            state.userinfo = step
        },
        addtotal(state, step) {
            state.total += step
        },
        subtotal(state, step) {
            state.total -= step
        },
        cleartotal(state, step) {
            //  总计清零
            state.total=step
        },
        selectall(state,step){
            state.total=step
        },
        //    在computer改变count值传给step,再改变state中的count
        cgecount(state, step) {
            state.count = step
        },
        // 保存勾选时的商品信息
        addcart(state,step){
            state.cartlist+=step
        },
        // 删除取消勾选时的商品信息
        delcart(state,step){
            state.cartlist-=step
        },
    },
    actions: {
    }
})



